/**
 * outsider.com.cn Inc.
 * Copyright (c) 2011-2022 All Rights Reserved.
 */
package com.yuanmeng.common.core.enums;

import com.yuanmeng.common.core.exception.ServiceException;

import lombok.Getter;

/**
 * @author outsider
 * @version Id: StatusEnum.java, v 0.1 2022/6/1 17:16 outsider Exp $$
 */
@Getter
public enum OrderChannelEnum {
    WECHAT_APPLET("WECHAT_APPLET", "微信小程序"),

    H5("H5", "H5"),

    ANDROID("ANDROID", "安卓客户端"),

    IOS("IOS", "IOS客户端");

    private String code;

    private String message;

    OrderChannelEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static void validateOrderChannel(String orderChannel) {
        int num = 0;
        for (OrderChannelEnum ENUM : OrderChannelEnum.values()) {
            if (ENUM.code.equals(orderChannel)) {
                num++;
            }
        }
        if (num == 0) {
            throw new ServiceException("请求参数非法：orderChannel");
        }
    }

    public static String codeQueryValue(String orderChannel) {
        for(OrderChannelEnum ENUM : OrderChannelEnum.values()) {
            if(ENUM.code.equals(orderChannel)) {
                return ENUM.getMessage();
            }
        }
        return "";
    }

    public static String valueQueryCode(String orderChannelValue) {
        for(OrderChannelEnum ENUM : OrderChannelEnum.values()) {
            if(ENUM.message.equals(orderChannelValue)) {
                return ENUM.getCode();
            }
        }
        return "";
    }
}